//
// Created by mingxi5 on 2019/1/9.
//

#include <stdio.h>
#include "function_test.h"



int fgetByrecursion(int arrInput[], int idatalen){
    if( idatalen<=2){
        return arrInput[1];
    } else if( 3 == idatalen ){
        return  arrInput[0] +  arrInput[1] +  arrInput[2];
    }else{
        return arrInput[0] + arrInput[1]*2 + arrInput[idatalen-1] + fgetByrecursion( arrInput, idatalen-2);
    }
}

int fgetByWhile( int arrInput[], int idatalen){
    int iret = 0;
    int iIndex = idatalen-1;
    while( iIndex>2 ){
        iret = iret + arrInput[0] + arrInput[1]*2 + arrInput[iIndex];
        iIndex = iIndex - 2;
    }
    if( 2 == iIndex){
        iret = iret + arrInput[0] +  arrInput[1] +  arrInput[2];
    }else{
        iret = iret +  arrInput[1];
    }
    return  iret;
}

int  getMinNumberThroughBrigeTest( ){
    int  arrStepInfo[] = { 1, 3, 4 ,6, 8, 9, 12};
    //int iret = fgetByrecursion( arrStepInfo, 7);
    int iret =  fgetByWhile( arrStepInfo, 7);
    return iret;
}



